#import "SchemePlugin.h"

@implementation SchemePlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"scheme"
            binaryMessenger:[registrar messenger]];
  SchemePlugin* instance = [[SchemePlugin alloc] init];
  [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"open" isEqualToString:call.method]) {
      NSURL *url = [NSURL URLWithString:call.arguments];
     if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
        }];
        result([NSNumber numberWithBool:true]);
     } else {
        result([NSNumber numberWithBool:false]);
     }
  } else {
    result(FlutterMethodNotImplemented);
  }
}

@end
